home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb-4.5 / dist / mmalloc / sbrk-sup.c < prev   
Encoding:
C/C++ Source or Header  |  1992-03-15  |  2.0 KB  |  65 lines

  1. /* Support for sbrk() regions.
  2.    Copyright 1992 Free Software Foundation, Inc.
  3.    Contributed by Fred Fish at Cygnus Support.   fnf@cygnus.com
  4.  
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9.  
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19.  
  20. #include "mmalloc.h"
  21.  
  22. extern PTR sbrk ();
  23.  
  24. /* The mmalloc() package can use a single implicit malloc descriptor
  25.    for mmalloc/mrealloc/mfree operations which do not supply an explicit
  26.    descriptor.  For these operations, sbrk() is used to obtain more core
  27.    from the system, or return core.  This allows mmalloc() to provide
  28.    backwards compatibility with the non-mmap'd version. */
  29.  
  30. struct mdesc *__mmalloc_default_mdp;
  31.  
  32. /* Initialize the default malloc descriptor if this is the first time
  33.    a request has been made to use the default sbrk'd region. */
  34.  
  35. struct mdesc *
  36. __mmalloc_sbrk_init ()
  37. {
  38.   PTR base;
  39.  
  40.   base = sbrk (0);
  41.   __mmalloc_default_mdp = (struct mdesc *) sbrk (sizeof (struct mdesc));
  42.   memset ((char *) __mmalloc_default_mdp, 0, sizeof (struct mdesc));
  43.   __mmalloc_default_mdp -> morecore = __mmalloc_sbrk_morecore;
  44.   __mmalloc_default_mdp -> base = base;
  45.   __mmalloc_default_mdp -> breakval = __mmalloc_default_mdp -> top = sbrk (0);
  46.   __mmalloc_default_mdp -> fd = -1;
  47.   return (__mmalloc_default_mdp);
  48. }
  49.  
  50. PTR
  51. __mmalloc_sbrk_morecore (mdp, size)
  52.   struct mdesc *mdp;
  53.   int size;
  54. {
  55.   PTR result = NULL;
  56.  
  57.   if ((result = sbrk (size)) != NULL)
  58.     {
  59.       mdp -> breakval += size;
  60.       mdp -> top += size;
  61.     }
  62.   return (result);
  63. }
  64.  
  65.